package io.unicorn.modules.water.service.impl;

import io.unicorn.common.config.MybatisPlusConfig;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.unicorn.common.utils.PageUtils;
import io.unicorn.common.utils.Query;

import io.unicorn.modules.water.dao.TDataDao;
import io.unicorn.modules.water.entity.TDataEntity;
import io.unicorn.modules.water.service.TDataService;


@Service("tDataService")
public class TDataServiceImpl extends ServiceImpl<TDataDao, TDataEntity> implements TDataService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key   = (String)params.get("key");
        String value = (String)params.get("value");

        String tableName = params.get("dept").toString();
        if(StringUtils.isNotEmpty(tableName)) {
            MybatisPlusConfig.myTableNameLocal.set("Gather_DB.dbo."+tableName);
        }
        IPage<TDataEntity> page = this.page(
                new Query<TDataEntity>().getPage(params),
                new QueryWrapper<TDataEntity>()
                        .like(StringUtils.isNotBlank(value) && StringUtils.isNotBlank(key), key, value)
        );

        return new PageUtils(page);
    }

}
